package com.ruoyi.test.controller;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.test.domain.Classroom;
import com.ruoyi.test.service.IClassroomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 班级Controller
 *
 * @author korol
 * @date 2023-11-11
 */
@Api(tags="班级管理")
@RestController
@RequestMapping("/test/classroom")
public class ClassroomController extends BaseController
{
    @Autowired
    private IClassroomService classroomService;

    /**
     * 查询班级列表
     */
    @ApiOperation("查询班级列表")
    @PreAuthorize("@ss.hasPermi('test:classroom:list')")
    @GetMapping("/list")
    public TableDataInfo list(Classroom classroom)
    {
        startPage();
        List<Classroom> list = classroomService.selectClassroomList(classroom);
        return getDataTable(list);
    }

    /**
     * 导出班级列表
     */
    @ApiOperation("导出班级列表")
    @PreAuthorize("@ss.hasPermi('test:classroom:export')")
    @Log(title = "班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Classroom classroom)
    {
        List<Classroom> list = classroomService.selectClassroomList(classroom);
        ExcelUtil<Classroom> util = new ExcelUtil<Classroom>(Classroom.class);
        util.exportExcel(response, list, "班级数据");
    }

    /**
     * 获取班级详细信息
     */
    @ApiOperation("获取班级详细信息")
    @PreAuthorize("@ss.hasPermi('test:classroom:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(classroomService.getById(id));
    }

    /**
     * 新增班级
     */
    @ApiOperation("新增班级")
    @PreAuthorize("@ss.hasPermi('test:classroom:add')")
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Classroom classroom)
    {
        return toAjax(classroomService.save(classroom));
    }

    /**
     * 修改班级
     */
    @ApiOperation("修改班级")
    @PreAuthorize("@ss.hasPermi('test:classroom:edit')")
    @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Classroom classroom)
    {
        return toAjax(classroomService.updateById(classroom));
    }

    /**
     * 删除班级
     */
    @ApiOperation("删除班级")
    @PreAuthorize("@ss.hasPermi('test:classroom:remove')")
    @Log(title = "班级", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(classroomService.removeByIds(Arrays.asList(ids)));
    }
}
